﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using MvcContrib.TestHelper;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Quiziqal.Application.Controllers;
using Quiziqal.Application.ViewModels;
using Quiziqal.Domain;
using Rhino.Mocks;
using SharpArch.Testing.NUnit;

namespace Quiziqal.Specifications.Core.Controllers
{
    [TestFixture]
    public class QuizControllerSpecs
    {
        [Test]
        public void list_should_assign_quizzes_to_view_model()
        {
            var controller = new QuizController(CreateMockedService());

            var result = controller.List().AssertViewRendered();

            var viewModel = result.ViewData.Model as QuizListViewModel;

            viewModel.ShouldNotBeNull("view model should not be null");
            viewModel.Quizzes.ShouldNotBeNull("quizzes should not be null");
            viewModel.Quizzes.Count.ShouldEqual(3);
        }

        private IQuiziqalService CreateMockedService()
        {
            IQuiziqalService service = MockRepository.GenerateStub<IQuiziqalService>();

            service
                .Expect(s => s.GetQuizzesByOwner(new User()))
                .Return(GetQuizzes());

            return service;
        }

        private ICollection<Quiz> GetQuizzes()
        {
            return new List<Quiz>
                       {
                           new Quiz { Name = "Quiz One"},
                           new Quiz { Name = "Quiz Two"},
                           new Quiz
                           { Name = "Quiz Three"}
                       };
        }
    }
}
